//
//  BaseViewController.swift
//  funcode
//
//  Created by Wan Jiading on 2016/11/23.
//  Copyright © 2016年 WanJiading. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {

//	var interactiveTransition: UIPercentDrivenInteractiveTransition!
//	
//    override func viewDidLoad() {
//        super.viewDidLoad()
//
//		self.navigationController?.delegate = self
//		self.view.isUserInteractionEnabled = true
//		
//		let panGR = UIPanGestureRecognizer(target: self, action: #selector(goBack(_:)))
//		self.view.addGestureRecognizer(panGR)
//    }
//	
//	@objc private func goBack(_ gesture: UIPanGestureRecognizer) {
//		self.customControllerPopHandle(gesture)
//	}
//	
//	private func customControllerPopHandle(_ gesture: UIPanGestureRecognizer) {
//		if self.navigationController?.childViewControllers.count == 1 {
//			return
//		}
//		
//		// interactiveTransition就是代理方法2返回的交互对象，我们需要更新它的进度来控制POP动画的流程。（以手指在视图中的位置与屏幕宽度的比例作为进度）
//		var process = gesture.translation(in: self.view).x/self.view.bounds.width
//		process = min(1.0, max(0.0, process))
//		
//		switch gesture.state {
//		case .began:
//			
//			// 此时，创建一个UIPercentDrivenInteractiveTransition交互对象，来控制整个过程中动画的状态
//			interactiveTransition = UIPercentDrivenInteractiveTransition()
//			_ = self.navigationController?.popViewController(animated: true)
//			
//			break
//		case .changed:
//			
//			// 更新手势完成度
//			interactiveTransition.update(process)
//			
//			break
//		case .ended, .cancelled:
//			
//			// 手势结束时，若进度大于0.5就完成pop动画，否则取消
//			if process > 0.5 {
//				interactiveTransition.finish()
//			} else {
//				interactiveTransition.cancel()
//			}
//			
//			interactiveTransition = nil
//			
//			break
//		case .failed, .possible:
//			break
//		}
//	}
//	
//	// MARK: - UINavigationControllerDelegate
//	
//	/// 返回一个实现了UIViewControllerAnimatedTransitioning协议的对象，即完成转场动画的对象
//	func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
//		if operation == UINavigationControllerOperation.pop {
//			DebugLog("UINavigationControllerOperation.pop")
//			return POPAnimation()
//		} else if operation == UINavigationControllerOperation.push {
//			DebugLog("UINavigationControllerOperation.push")
//			return PushAnimation()
//		}
//		
//		return nil
//	}
//	
//	/// 返回一个实现了UIViewControllerInteractiveTransitioning协议的对象，即完成动画交互（动画进度）的对象
//	func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
//		if animationController.isKind(of: POPAnimation.classForCoder()) {
//			return interactiveTransition
//		}
//		return nil
//	}
	
}
